package org.blogwu.learn.threadLearn.使用unsafe实现原子性;

import sun.misc.Unsafe;

import java.util.concurrent.atomic.AtomicInteger;

public class Test1 {
    public final static int a;

    static {
        a = 0;
    }


    // setup to use Unsafe.compareAndSwapInt for updates
    private static final Unsafe unsafe = null;
    private static final long valueOffset;

    static {
        try {
            valueOffset = unsafe.objectFieldOffset
                    (AtomicInteger.class.getDeclaredField("value"));
        } catch (Exception ex) {
            throw new Error(ex);
        }
    }

}